<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">库存查询</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="名称" prop="productName">
          <el-input
            v-model="queryParams.productName"
            placeholder="请输入产品名称"
            clearable
            size="small"
            style="width:230px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
           <el-button type="primary" icon="el-icon-search" size="mini" class="list-search btn-success" color="#5ED4D4"
            @click="handleQuery"
          >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" class="list-search"
            @click="resetQuery"
          >重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="productStockList" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品名称" align="center" prop="productName" :show-overflow-tooltip="true" />
        <el-table-column label="产品批号" align="center" prop="batchNumber" :show-overflow-tooltip="true" />
        <el-table-column label="库存数量" align="center" prop="store" :show-overflow-tooltip="true" />
        <el-table-column label="主计量单位" align="center" prop="productSpace" :show-overflow-tooltip="true" />
        <el-table-column label="辅助计量单位" align="center" prop="productSpace" :show-overflow-tooltip="true" />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listStock } from "@/api/system/stock/stock";

export default {
  name: "stock",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 仓库数据
      productStockList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: undefined,
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      listStock(this.addDateRange(this.queryParams)).then((res) => {
        this.productStockList = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>
